import unittest
from xml.etree.ElementTree import ElementTree as ET
from Config import CONFIG
import HTMLTestReportCN

# 原来加的代码，没卵用，先注释不删除
# config_elements = ET(file='./config.xml').findall('.//全局配置/*')
# # 存储config.py
# for i in config_elements:
#     CONFIG[i.tag] = i.text

# 读取
config_elements = ET(file='./config.xml').findall('.//你大爷/*')
suite = unittest.TestSuite()
for i in config_elements:
    case_info = i.tag
    file_name = i.tag.split('-')[0]
    class_name = i.tag.split('-')[1]
    method_name = i.tag.split('-')[2]
    try:
        T = f'''from cases.{file_name} import {class_name}
suite.addTest( {class_name}('{method_name}'))'''
        exec(T)
    except ValueError:
        T1 = f'''from cases.{file_name} import {class_name}
t = unittest.TestLoader().getTestCaseNames({class_name})
for name in t:
    if name.startswith('{method_name}'):
        suite.addTest({class_name}(name))'''
        exec(T1)
unittest.TextTestRunner().run(suite)
# fp=open(file='./Report/1.HTML',mode='wb')
# HTMLTestReportCN.HTMLTestRunner(stream=fp).run(suite)
# fp.close()

